package com.baihan.angus.app.game.busshow.adps;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.busshow.R;
import com.baihan.angus.app.game.common.bean.entity.ClueEntity;

public class ClueAdp extends BaseAdp<ClueEntity, ClueAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_clue, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        ClueEntity clueData = getItem(position);

        vh.tvTitle.setText(clueData.getTitle());
        vh.tvContent.setText(clueData.getContent());
        if (clueData.getClue_type() == 0) {//0-公开 1-私有
            vh.tvType.setText("公开");
            vh.tvType.setBackgroundResource(R.mipmap.ic_btn_green);
        } else if (clueData.getClue_type() == 1) {
            vh.tvType.setText("私有");
            vh.tvType.setBackgroundResource(R.mipmap.ic_btn_red);
        }

        vh.flItem.setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvTitle, tvType, tvContent;
        ImageView ivRedPoint;
        FrameLayout flItem;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tvTitle);
            tvType = itemView.findViewById(R.id.tvType);
            tvContent = itemView.findViewById(R.id.tvContent);
            ivRedPoint = itemView.findViewById(R.id.ivRedPoint);
            flItem = itemView.findViewById(R.id.flItem);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
